package com.graphics.enginedemo.simpledemo;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.graphics.enginedemo.R;

import java.util.ArrayList;
import java.util.List;


/**
 * Graphics Demo List
 */
public class GraphicsDemoListActivity extends ListActivity {

    public final static String KEY_CONTENT_VIEW = "ContentView";
    public final static String VIEW_NAME_PREFIX = "com.graphics.enginedemo.simpledemo.";

    private List<String> mItemTitle = new ArrayList<String>();
    private List<String> mItemViewName = new ArrayList<String>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addItems();
        ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.main_list, mItemTitle);
        setListAdapter(fileList);
        setContentView(R.layout.main);
    }

    private void addItem(String title, String viewName) {
        mItemTitle.add(title);
        if (viewName.indexOf('.') < 0) {
            mItemViewName.add(VIEW_NAME_PREFIX + viewName);
        } else if (viewName.indexOf(' ') >= 0) {
            mItemViewName.add(viewName.substring(viewName.indexOf(' ') + 1));
        } else {
            mItemViewName.add(viewName);
        }
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        if (position >= 0 && position < mItemViewName.size()) {
            Intent intent = new Intent(this, GraphicsDemoActivity.class);
            intent.putExtra(KEY_CONTENT_VIEW, mItemViewName.get(position));
            startActivity(intent);
        }
    }

    /**
     * TODO: 在这里添加具体的GLView和名称
     */
    void addItems() {
        addItem("GLViewSimpleDemo", GLViewSimpleDemo.class.toString());
    }


}
